//
//  CheckNetwork.m
//  GlobalSetting
//
//  Created by hanf on 15/9/7.
//  Copyright (c) 2015年 hanf. All rights reserved.
//

#import "CheckNetwork.h"
#import "AFNetworking.h"

@implementation CheckNetwork

+ (CheckNetwork *)checkNetwork{
    static CheckNetwork *checkNetwork = nil;
    static dispatch_once_t oneToken;
    dispatch_once(&oneToken, ^{
        checkNetwork = [[self alloc] init];
    });
    return checkNetwork;
}

- (BOOL)isNetworkReachable
{
    AFNetworkReachabilityManager *manger = [AFNetworkReachabilityManager sharedManager];
    [manger startMonitoring];
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:{
                WLog(@"无网络");
                [WShareUtil showAlert:@"提示" message:@"网络已断开，请检查网络连接"];

                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                WLog(@"WiFi网络");
                
                //                    [self alertWithMsg:@"WiFi网络"];
                break;
                
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                WLog(@"无线网络");
                //                [self alertWithMsg:@"无线网络"];
                BOOL isWWAN = [[NSUserDefaults standardUserDefaults] boolForKey:@"isWWAN"];
                if (!isWWAN) {
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"STOPPLAY" object:nil];
                }
                break;
            }
            default:
                break;
        }
    }];
    return manger.isReachable;
}


@end
